package com.ruoyi.web.controller.report;

import com.ruoyi.collectQuery.domain.HouseCollectQueryT;
import com.ruoyi.collectQuery.service.IHouseCollectQueryTService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小区汇总
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/report/collectQuery")
public class HouseCollectQueryTController extends BaseController
{
    @Autowired
    private IHouseCollectQueryTService houseCollectQueryTService;

    /**
     * 查询资金汇总列表
     */
   @GetMapping("/list")
    public TableDataInfo list(HouseCollectQueryT houseCollectQueryT)
    {
        startPage();
        List<HouseCollectQueryT> list = houseCollectQueryTService.selectHouseCollectQueryTList(houseCollectQueryT);
        if (list.size()!=0) {
            if (getDataTableSumJudge(list)) {
                HouseCollectQueryT houseCollectQueryVO = houseCollectQueryTService.selectHouseCollectQuerySum(houseCollectQueryT);
                houseCollectQueryVO.setAreaName("合计");
                list.add(houseCollectQueryVO);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出返还列表
     */
    @Log(title = "小区汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseCollectQueryT houseCollectQueryT)
    {
        List<HouseCollectQueryT> list = houseCollectQueryTService.selectHouseCollectQueryTList(houseCollectQueryT);
        if(getDataTableSumJudge(list)){
            HouseCollectQueryT houseCollectQueryVO = houseCollectQueryTService.selectHouseCollectQuerySum(houseCollectQueryT);
            houseCollectQueryVO.setAreaName("合计");
            list.add(houseCollectQueryVO);
        }
        ExcelUtil<HouseCollectQueryT> util = new ExcelUtil<HouseCollectQueryT>(HouseCollectQueryT.class);
        util.exportExcel(response, list, "小区资金汇总数据");
    }


}
